package com.mrxu.monitor.controller;


import com.mrxu.monitor.base.ResultObj;
import com.mrxu.monitor.config.MonitorProperties;
import com.mrxu.monitor.notice.MessageCenterService;
import com.mrxu.monitor.notice.NoticeType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import static com.mrxu.monitor.base.ResultObj.success;

@Controller
@Slf4j
@RequestMapping("/"+MonitorProperties.MONITORPREFIX)
public class MonitorTestController {

    @Autowired
    private MessageCenterService messageCenterService;

    @ResponseBody
    @RequestMapping(value = "/testHttpState500.json",produces = "application/json;charset=UTF-8")
    public ResponseEntity<String> testHttpState500() {
        return new ResponseEntity<String>("测试http 500状态码", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    @ResponseBody
    @RequestMapping(value = "/timeout.json",produces = "application/json;charset=UTF-8")
    public ResultObj<Object> timeout() throws InterruptedException {
        Thread.sleep(2000l);
        return success();
    }

    @ResponseBody
    @RequestMapping(value = "/sendNoticeMsg.json",produces = "application/json;charset=UTF-8")
    public ResultObj<Object> sendNoticeMsg() {
        messageCenterService.sendNoticeMsg("测试消息",NoticeType.ErrorCount);
        return success();
    }

}
